'use strict';

angular.module('simon', [
	'ngCookies',
	'ngRoute',
	'ngResource',
	'ngSanitize', 
	'simon.filters',
	'simon.services',
	'simon.controllers',
	'ui.bootstrap',
	'angucomplete'
	])
.config(function ($routeProvider, $httpProvider) {
	$routeProvider.when('/clientes-list', {auth: true, templateUrl: 'views/clientes-list.html', controller: 'ClienteCtrl'});
	$routeProvider.when('/fornecedores-list', {auth: true, templateUrl: 'views/fornecedores-list.html', controller: 'FornecedorCtrl'});
	$routeProvider.when('/funcionarios-list', {auth: true, templateUrl: 'views/funcionarios-list.html', controller: 'FuncionarioCtrl'});
	$routeProvider.when('/condPagto-list', {auth: true, templateUrl: 'views/cond-pagto-list.html', controller: 'CondPagtoCtrl'});
	$routeProvider.when('/produtos-list', {auth: true, templateUrl: 'views/produtos-list.html', controller: 'ProdutoCtrl'});
	$routeProvider.when('/usuarios-list', {auth: true, templateUrl: 'views/usuarios-list.html', controller: 'UsuarioCtrl'});
	$routeProvider.when('/vendas-list', {auth: true, templateUrl: 'views/vendas-list.html', controller: 'VendaListCtrl'});
	$routeProvider.when('/vendas-detail', {auth: true, templateUrl: 'views/vendas-detail.html', controller: 'VendaCtrl'});
	
	/* CORS... */
	/* http://stackoverflow.com/questions/17289195/angularjs-post-data-to-external-rest-api */
	$httpProvider.defaults.useXDomain = true;
	delete $httpProvider.defaults.headers.common['X-Requested-With'];
})
.run(['$templateCache','$interpolate', function($templateCache, $interpolate) {
	var startSym = $interpolate.startSymbol();
    var endSym = $interpolate.endSymbol();
	$templateCache.put('/dialogs/error.html','<div class="modal-header dialog-header-error"><button type="button" class="close" ng-click="close()">&times;</button><h4 class="modal-title text-danger"><span class="glyphicon glyphicon-warning-sign"></span> <span ng-bind-html="header"></span></h4></div><div class="modal-body text-danger" ng-bind-html="msg"></div><div class="modal-footer"><button type="button" class="btn btn-default" ng-click="close()">Fechar</button></div>');
	$templateCache.put('/dialogs/wait.html','<div class="modal-header dialog-header-wait"><h4 class="modal-title"><span class="glyphicon glyphicon-time"></span> Por favor, aguarde!</h4></div><div class="modal-body"><p ng-bind-html="msg"></p><div class="progress progress-striped active"><div class="progress-bar progress-bar-info" ng-style="getProgress()"></div><span class="sr-only">'+startSym+'progress'+endSym+'% Complete</span></div></div>');
	$templateCache.put('/dialogs/notify.html','<div class="modal-header dialog-header-notify"><button type="button" class="close" ng-click="close()" class="pull-right">&times;</button><h4 class="modal-title text-info"><span class="glyphicon glyphicon-info-sign"></span> '+startSym+'header'+endSym+'</h4></div><div class="modal-body text-info" ng-bind-html="msg"></div><div class="modal-footer"><button type="button" class="btn btn-primary" ng-click="close()">OK</button></div>');
	$templateCache.put('/dialogs/confirm.html','<div class="modal-header dialog-header-confirm"><button type="button" class="close" ng-click="no()">&times;</button><h4 class="modal-title"><span class="glyphicon glyphicon-check"></span> Por favor, confirme!</h4></div><div class="modal-body">Tem certeza que deseja excluir este registro?</div><div class="modal-footer"><button type="button" class="btn btn-default" ng-click="yes()">Sim</button><button type="button" class="btn btn-primary" ng-click="no()">Cancelar</button></div>');
}]);

angular.module('simon.filters', []);
angular.module('simon.services', []);
angular.module('simon.controllers', []);
